package com.stylefeng.guns.rest.modular.App.controller;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.rest.Tools.Result;
import com.stylefeng.guns.rest.modular.App.model.OrderCustomerCode;
import com.stylefeng.guns.rest.modular.App.service.IOrderCustomerCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
/**
 * 乘客评分
 *
 * @author sasazaixian
 * @Date 2018-12-25 10:45
 */
@Controller
@RequestMapping(value = {"/gunsApi/auth/orderCustomerCode"})
@Api(value = "乘客评分操作相关api", tags = {"乘客评分操作接口"})
public class OrderCustomerCodeController extends BaseController {
    @Autowired
    private IOrderCustomerCodeService orderCustomerCodeService;
    /**
     * 获取乘客评分列表
     * @param orderCustomerCode    
     * @return	
     */
    @ApiOperation(value = "获取乘客评分列表", notes = "获取乘客评分列表", httpMethod = "POST")
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    public Result list(
        @RequestBody @ApiParam(name = "orderCustomerCode", value = "乘客评分对象")OrderCustomerCode orderCustomerCode) {
        try {            
            return Result.success( orderCustomerCodeService.selectListOrderCustomerCode(orderCustomerCode,getToken()));
        }catch(Exception e){
           return  Result.error(e.getMessage(),500100);
        }
    }
    /**
     * 通过主键获取乘客评分对象
     * @param id
     * @return
     */
    @ApiOperation(value = "通过主键获取乘客评分对象", notes = "通过主键获取乘客评分对象", httpMethod = "GET")
    @GetMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Result getById(
            @ApiParam(name = "id", value = "主键ID", required = true) @RequestParam(value = "id", required = true) String  id
    ) {
        try {
            return Result.success(orderCustomerCodeService.findOrderCustomerCodeById(id,null));
        }catch(Exception e){
           return  Result.error(e.getMessage(),500100);
        }
    }

    /**
     * 新增乘客评分数据
     *
     * @param orderCustomerCode 
     * @param result
     * @return
     */
    @ApiOperation(value = "新增乘客评分数据", notes = "新增乘客评分数据", httpMethod = "POST")
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Result add(@RequestBody @ApiParam(name = "orderCustomerCode ", value = "乘客评分对象")OrderCustomerCode orderCustomerCode ,BindingResult result
    ) {
        if (result.hasErrors()) {
            return Result.error("参数异常！",500100);
        }

        try {
            orderCustomerCodeService.insertOrderCustomerCode(orderCustomerCode,null);
            return Result.success();
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
	private String getToken(){		
		return getHttpServletRequest().getHeader("Authorization").substring(7);
    }
}
